﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OF.Component.BLL;
using OF.Utility;
using MessageBox = System.Windows.Forms.MessageBox;

namespace Tools
{
    public partial class GenerateBizTypes : Form
    {
        public GenerateBizTypes()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var listNode = new List<Node>();
            var listGroup = BizTypeGroupOperate.QueryList(m => true);
            listGroup.ForEach(m =>
            {
                var node = new Node();
                node.text = m.GroupName;
                node.value = m.GroupID;
                var listBizType = BizTypeOperate.QueryList(n => n.GroupID == m.GroupID);
                var childs = new List<NodeLastChild>();
                listBizType.ForEach(c =>
                {
                    var nodeChild = new NodeLastChild
                    {
                        text = c.BizTypeName,
                        value = c.BizTypeID
                    };
                    childs.Add(nodeChild);
                });
                node.childs = childs;
                listNode.Add(node);
            });

            var szSaveFilePath = Path.Combine(Application.StartupPath, "bizTypeData.json");
            listNode.ToJSON(szSaveFilePath);

            System.Windows.Forms.MessageBox.Show(this, "json文件已生成");
            System.Diagnostics.Process.Start(szSaveFilePath);
        }
    }
}
